package ru.osu.acm.common.entities;

import ru.osu.acm.testing.Utils;

import java.sql.Timestamp;
import java.util.Date;

/**
 * User: Aleksey
 * Date: 18.02.2009
 * Time: 13:54:43
 */

public class Submission implements Comparable<Submission> {
    private int id;
    private Person person;
    private Team team;
    private Problem problem;
    private int status;
    private int plagStatus;
    private double plagCoeff;
    private String compiler;
    private int time;
    private int test; // TODO: make object link ???
    private int contest; // TODO: make object link
    private Timestamp submitted;
    private String source;

    public int compareTo(Submission o) {
        if (id != o.id) {
            return o.id - id;
        }
        return 0;
    }

    public static final String[] statuses = new String[]{"Received", "Queued", "Compiling", "Running", "Accepted",
            "Compile Error", "Runtime Error", "Wrong Answer", "Time Limit Exceeded", "Memory Limit Exceeded",
            "Output Limit Exceeded", "Check Failed", "Problem Not Found", "No Output File", "Dummy"};
    public static final String[] plagiarismStatuses = new String[]{"Queued", "Confirmed", "Suspect", "Illegal", "-", "Testing"};

    private final String[] colors = new String[]{"black", "black", "green", "blue", "darkred",
            "darkblue", "darkblue", "darkblue", "darkblue", "darkblue",
            "darkblue", "orange", "orange", "darkblue", "orange"};

    public static final String[] plagiarismColors = new String[]{"black", "darkgreen", "darkblue", "darkred", "black", "darkblue"};

    public Submission(int id, Person person, Team team, Problem problem, int status, int plagStatus, double plagCoeff, String compiler, int time, int test, int contest, Timestamp submitted, String source) {
        this.id = id;
        this.person = person;
        this.team = team;
        this.problem = problem;
        this.status = status;
        this.plagStatus = plagStatus;
        this.plagCoeff = plagCoeff;
        this.compiler = compiler;
        this.time = time;
        this.test = test;
        this.contest = contest;
        this.submitted = submitted;
        this.source = source;
    }

    public String getColor() {
        return colors[status];
    }

    public void setColor(String color) {
    }

    public String getPlagColor() {
        return plagiarismColors[plagStatus];
    }

    public void setPlagColor(String plagColor) {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Person getUser() {
        return person;
    }

    public void setUser(Person person) {
        this.person = person;
    }

    public String getStatus() {
        return statuses[status];
    }

    public void setStatus(String status) {
    }

    public String getCompiler() {
        return compiler;
    }

    public void setCompiler(String compiler) {
        this.compiler = compiler;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public int getTest() {
        return test;
    }

    public void setTest(int test) {
        this.test = test;
    }

    public int getContest() {
        return contest;
    }

    public void setContest(int contest) {
        this.contest = contest;
    }

    public Problem getProblem() {
        return problem;
    }

    public void setProblem(Problem problem) {
        this.problem = problem;
    }

    public Date getSubmitted() {
        return submitted;
    }

    public void setSubmitted(Timestamp submitted) {
        this.submitted = submitted;
    }

    public String getPlagStatus() {
        return plagiarismStatuses[plagStatus];
    }

    public void setPlagStatus(String plagStatus) {
    }

    public double getPlagCoeff() {
        return plagCoeff;
    }

    public void setPlagCoeff(double plagCoeff) {
        this.plagCoeff = plagCoeff;
    }

    public String getSource() {
        return source;
    }

    public Team getTeam() {
        return team;
    }

    public void setTeam(Team team) {
        this.team = team;
    }

    public String getAuthorFullname() {
        String fullname;
        if (person != null) {
            fullname = person.getName() + " " + person.getSurname();
        }
        else if (team != null) {
            fullname = team.getTeamname();
        }
        else {
            fullname = "";
        }
        return fullname;
    }

    public String getFilename() {
        String filename = "solution";
        if (this.getCompiler().equals("java")) {
            filename = Utils.getJavaClassName(this.getSource());
        }
        return filename;
    }
}
